package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.UserService;
import com.mall.user.annotation.Anonymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * create by heyyon 2020-12-20 14:57
 * 用户注册激活
 */
@RestController
public class UserVerifyController {
    @Reference(check = false)
    UserService userService;
    @Anonymous
    @GetMapping("user/verify")
    public ResponseData userVerify(String username, String uid) {
        UserVerifyRequest request = new UserVerifyRequest();
        request.setUserName(username);
        request.setUuid(uid);
        //先去用户验证表中查询给定的用户名和唯一激活码是否正确
        UserVerifyResponse response = userService.countByNameAndUid(request);
        if (!response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil<>().setErrorMsg(response.getMsg());
        }
        //改变verify标志
        UserVerifyResponse userVerifyResponse=userService.updateVerifyTagByName(request);
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil<>().setErrorMsg(response.getMsg());
        }
        return new ResponseUtil().setData(null);
    }
}
